import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @author MI
 * @version 1.0
 * @date 2020/10/25 9:51
 */

public class RockMQSendMsg {

    public static final String producerGroup = "myproducer-group";

    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {

        //1 创建消息生产者，并设置生产组名
        final DefaultMQProducer mqProducer = new DefaultMQProducer(producerGroup);
        //2 为生产者设置NameServer地址
        mqProducer.setNamesrvAddr("192.168.226.120:9876");

        //3 启动生产者
        mqProducer.start();
        //4 构建消息对象，只要是设置主题，标签 内容
        final Message message = new Message("myTopic", "myTag", ("test rocketmq message").getBytes());

        //5 发送消息
        final SendResult sendResult = mqProducer.send(message, 10000);
        System.out.println(sendResult);

        //6 关闭生产者
        mqProducer.shutdown();
    }
}
